package org.shezhua.android.i18n;

import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.TableItem;
import org.shezhua.android.i18n.model.ResValues;

public class AndroidCellModifier implements ICellModifier {
	private TableViewer tv;

	public AndroidCellModifier(TableViewer tv) {
		this.tv = tv;
	}
	
	@Override
	public boolean canModify(Object element, String property) {
		return !"key".equals(property);
	}

	@Override
	public Object getValue(Object element, String property) {
		ResValues values = (ResValues) element;
		return values != null ?values.getString(property) : null;
	}

	@Override
	public void modify(Object element, String property, Object value) {
		TableItem item = (TableItem) element;
		ResValues values = (ResValues) item.getData();
		if(values != null) {
			values.setString(property, value);
		}
		tv.update(values, null);
	}
}
